<template>
	<view class="outBox">
		<u-navbar leftText="绑定我的哥哥" leftIconColor="#fff" :autoBack="true" bgColor="rgba(0, 0, 0, 0.6)">
			<view class="left-slot" slot="left">
				<u-icon name="arrow-left" color="#fff"></u-icon>
				<text>{{ '绑定我的哥哥' }}</text>
			</view>
		</u-navbar>
		<video :src="videoUrl + '/mp4/1.mp4'" autoplay :controls="false" loop
			object-fit="cover"></video>
<!--		<video :src="videoPath" autoplay :controls="false" loop object-fit="cover"></video>-->
		<view class="bgBox"></view>
		<view class="content" :style="{
			marginTop:menuHeight + 'px',
		}">
			<view class="contentInner">
				<view class="searchBox">
					<u-search searchIconSize="0" height="90rpx" :inputStyle="{
						paddingRight:'60rpx'
					}" bgColor="#141521" :clearabled="false" color="#fff" border-color="#21253B" placeholder="请输入手机号"
						v-model="searchValue" :showAction="false" actionText="123123"
						@search="searchManager"></u-search>
					<view class="icon" @click="searchManager">
						<u-icon name="search" color="#fff" size="30"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="item" v-if="managerInfo.name">
						<view class="left">
							<view class="info">
								<text>{{managerInfo.name || '-'}}</text>
							</view>
						</view>
						<view class="right">
							<view class="btn" @click="handleBinding()">
								绑定
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-modal :show="showDia" :title="'是否绑定'" @cancel="showDia = false" @confirm="comfirmBinding"
				:showCancelButton="true" :content='content'></u-modal>
		</view>
	</view>
</template>

<script>
	import {
		getWXStatusHeight,saveVideoFile
	} from '@/utils/index.js'
	import {
		findCustomerManagerDetail,
		bindCustomerApi
	} from '../../api/api'
	export default {
		data() {
			return {
				videoUrl: this.$videoUrl,
				// 胶囊的宽度
				barWidth: 0,
				menuHeight: 0,
				searchValue: '', // 搜索值
				showDia: false, // 确定绑定
				content: '确认是否绑定哥哥',
				managerInfo: {}, // 客户经理详情
				videoPath:'',
			}
		},
		onLoad() {
			let obj = getWXStatusHeight()
			this.barWidth = obj.barWidth + 3
			this.menuHeight = obj.menuHeight
			this.getVideoFile()
		},
		methods: {
			// 获取视频资源文件
			async getVideoFile() {
				const res = await saveVideoFile()
				this.videoPath = res
			},
			handleBinding() {
				this.showDia = true
			},
			// 确认绑定
			async comfirmBinding() {
				this.showDia = false

				const res = await bindCustomerApi(this.managerInfo.id)
				if (res.code == 200) {
					uni.$u.toast('绑定成功');
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			},
			// 搜索
			async searchManager() {
				if (this.searchValue == '') {
					return this.$toast("请输入手机号")
				}

				const res = await findCustomerManagerDetail(this.searchValue)
				console.log(res, "Res");
				if (res.data.name) {
					this.managerInfo = res.data
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bgBox {
		width: 100vw;
		height: 100vh;
		position: fixed;
		z-index: 1;
		background: rgba(0, 0, 0, 0.6);
	}

	.items {
		margin-top: 30rpx;

		.item {
			height: 110rpx;
			padding: 0 30rpx;
			color: #fff;
			background: rgba(22, 24, 40, 0.8);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			border: 2rpx solid #21253B;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.btn {
				width: 156rpx;
				height: 64rpx;
				background: linear-gradient(267deg, #CC34B3 0%, #541A66 100%);
				border-radius: 200rpx 200rpx 200rpx 200rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				text {
					color: #fff;
				}
			}
		}
	}

	.searchBox {
		position: relative;
		margin: 0 40rpx;

		.icon {
			position: absolute;
			right: 30rpx;
			top: 50%;
			transform: translateY(-50%);
		}
	}

	video {
		width: 100%;
		height: 100%;
		object-fit: cover;
		/* 确保视频填充整个容器，可能会裁剪视频 */
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 0;
	}

	.content {
		position: relative;
		padding: 20rpx 0;
		box-sizing: border-box;
		position: relative;
		z-index: 99;
		flex: 1;
	}

	.left-slot {
		color: #fff;
		display: flex;
		align-items: center;

		image {
			width: 40rpx;
			margin-right: 30rpx;
		}
	}

	.outBox {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
	}
</style>
